package implementation;

import model.HasSource;
import model.Operation;
import operand.MyError;
import operand.MyValue;
import operand.Operand;

/**
 * The {@link IntegerAddition} is the division {@link Operation} on the data type {@link Integer}.
 *
 */
public class IntegerDivision extends Operation<Integer>{

	/**
	 * Constructor of {@link IntegerDivision}.
	 * @param dividend is the dividend.
	 * @param divisor is the divisor.
	 */
	public IntegerDivision(final HasSource<Operand<Integer>> dividend,
			final HasSource<Operand<Integer>> divisor) {
		super(dividend, divisor);
	}

	@Override
	protected Operand<Integer> calculateTransitive(final MyValue<Integer> firstValue,
			final MyValue<Integer> secondValue) {
		Operand<Integer> result;
		if(secondValue.getValue() == 0){
			result = new MyError<Integer>("Div 0");
		} else{
			result = new MyValue<Integer>(firstValue.getValue() / secondValue.getValue());
		}
		return result;
	}

}
